package com.yhn.init.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yhn.init.common.BaseResponse;
import com.yhn.init.common.DeleteRequest;
import com.yhn.init.common.ResultUtils;
import com.yhn.init.model.dto.details.DetailsAddRequest;
import com.yhn.init.model.dto.details.DetailsQueryRequest;
import com.yhn.init.model.dto.details.DetailsUpdateRequest;
import com.yhn.init.model.vo.DetailsVO;
import com.yhn.init.service.DetailsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 货单信息
 *
 * @author yhnyhn123
 * @email 2236751002@qq.com
 * @date 2024-03-08 20:36:42
 */
@RestController
@RequestMapping("/details")
public class DetailsController {

    @Resource
    private DetailsService detailsService;

    /**
     * 列表,分页
     */
    @GetMapping("/list")
    //@SaCheckPermissions("furniture/details/list")
    public BaseResponse<Page<DetailsVO>> listByPage(@RequestBody DetailsQueryRequest detailsQueryRequest) {
        Page<DetailsVO> page = detailsService.queryPage(detailsQueryRequest);
        return ResultUtils.success(page);
    }


    /**
     * 获取单个信息
     */
    @GetMapping("/info/{id}")
    //@SaCheckPermissions("furniture/details/info")
    public BaseResponse<DetailsVO> getInfoById(@PathVariable("id") Long id) {
        DetailsVO details = detailsService.getInfoById(id);

        return ResultUtils.success(details);
    }


    /**
     * 厂长填写出货单信息
     *
     * @param detailsAddRequest
     * @return
     */
    @PostMapping("/save")
    @SaCheckPermission(value = {"/furniture/details/add", "root"}, mode = SaMode.OR)
    public BaseResponse<Long> save(@RequestBody DetailsAddRequest detailsAddRequest) {
        Long newId = detailsService.saveDetails(detailsAddRequest);

        return ResultUtils.success(newId);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@SaCheckPermissions("furniture/details/update")
    public BaseResponse<Boolean> update(@RequestBody DetailsUpdateRequest detailsUpdateRequest) {
        boolean result = detailsService.updateDetails(detailsUpdateRequest);

        return ResultUtils.success(result);
    }


    /**
     * 删除
     */
    @PostMapping("/delete")
    //@SaCheckPermissions("furniture/details/delete")
    public BaseResponse<Boolean> delete(@RequestBody DeleteRequest deleteRequest) {
        boolean result = detailsService.deleteById(deleteRequest);
        return ResultUtils.success(result);
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteBatch")
    //@SaCheckPermissions("furniture/details/delete")
    public BaseResponse<Boolean> deleteBatch(@RequestBody Long[] ids) {
        boolean result = detailsService.deleteBatchByIds(ids);
        return ResultUtils.success(result);
    }
}
